home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / Catalog Service Access Module / DTS Sample CSAM / Src / AddDirectory.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-23  |  3.5 KB  |  126 lines  |  [TEXT/KAHL]

  1. /*
  2.  * AddDirectory.c
  3.  * Copyright © 1992-93 Apple Computer Inc. All Rights Reserved.
  4.  *
  5.  * Add a directory (expressed as a FSSpec) to our private list of
  6.  * directories. Note that AddDirectory allocates memory and, hence,
  7.  * must not be called from an I/O completion or interrupt routine.
  8.  */
  9. #include "DTSSampleDSAM.h"
  10.  
  11.     
  12. OSErr
  13. AddDirectory(
  14.         register DTSSampleDSAMInfoPtr    infoPtr,
  15.         DirParamBlockPtr                pb
  16.     )
  17. {
  18.         OSErr                    status;
  19.         DirectoryInfoPtr        newDirectory;
  20.         RecordID                rid;
  21.         short                    setupRefNum;
  22.         short                    pabRefNum;
  23.         FSSpec                    pabSpec;
  24.         AttributeType            attributeType;
  25.         AuthGetLocalIdentityPB    authParamBlock;
  26.  
  27.  
  28.         LogText('AddS', "\pAddDirectory entry");
  29.         LogRString('AddD', pb->addDSAMDirectoryPB.directoryName);
  30.         status = ADASGetOCESetupInfo(&rid, &setupRefNum);
  31.         LogStatus('AddD', status, "\pADASGetOCESetupInfo");
  32.         if (status == noErr) {
  33.             OCECToRString(
  34.                 kPDAliasAttrTypeBody,            /* Note: C-string        */
  35.                 smRoman,
  36.                 (RStringPtr) &attributeType,
  37.                 kAttributeTypeMaxBytes
  38.             );
  39.         }
  40.         if (status == noErr) {
  41.             rid.local.recordName = NULL;
  42.             rid.local.recordType = NULL;
  43.             rid.rli = NULL;
  44.             OCECopyCreationID(
  45.                 &pb->addDSAMDirectoryPB.directoryRecordCID,
  46.                 &rid.local.cid
  47.             );
  48.             pabSpec.vRefNum = 0;
  49.             /*
  50.              * Get the local identity. If this fails, set the local
  51.              * identity to zero (guest).
  52.              */
  53.             (void) AuthGetLocalIdentity(
  54.                         (AuthParamBlockPtr) &authParamBlock,
  55.                         FALSE                /* Synchronous        */
  56.                     );
  57.             LogStatus('AddD', authParamBlock.ioResult, "\pAuthGetLocalIdentity");
  58.             if (authParamBlock.ioResult != noErr)
  59.                 authParamBlock.theLocalIdentity = 0;    /* Use "guest" identity        */
  60.             status = ADASLookupAttributeValue(
  61.                         &rid, 
  62.                         setupRefNum, 
  63.                         authParamBlock.theLocalIdentity, /* Use owner's identity    */
  64.                         kAliasBufferSize,
  65.                         FALSE,                         /* Don't include start point    */
  66.                         &attributeType,
  67.                         OCENullCID(),
  68.                         (long) &pabSpec,
  69.                         (ForEachAttrValue) GetPABFSSpecCB
  70.                     );
  71.             LogStatus('AddD', status, "\pADASLookupAttributeValue");
  72.         }
  73.         if (status == noErr) {
  74.             status = ADASOpenPAB(
  75.                         &pabSpec,
  76.                         fsRdWrPerm,
  77.                         &pabRefNum
  78.                     );
  79.             LogStatus('AddD', status, "\pADASOpenPAB");
  80.         }
  81.         if (status == noErr) {
  82.             /*
  83.              * Note that the directory block is created in the current heap.
  84.              * Will this be the application heap or the system heap?
  85.              * What happens if the application quits?
  86.              */
  87.             newDirectory = (DirectoryInfoPtr) NewPtrClear(sizeof (DirectoryInfo));
  88.             status = MemError();
  89.             LogError('AddD', status);
  90.             if (status == noErr) {
  91.                 newDirectory->refNum = pabRefNum;
  92.                 OCECopyCreationID(
  93.                     &pb->addDSAMDirectoryPB.directoryRecordCID,
  94.                     &newDirectory->creationID
  95.                 );
  96.                 OCECopyDirDiscriminator(
  97.                     &pb->addDSAMDirectoryPB.discriminator,
  98.                     &newDirectory->discriminator
  99.                 );
  100.                 OCECopyRString(
  101.                     (RString *) pb->addDSAMDirectoryPB.directoryName,
  102.                     (RString *) &newDirectory->directoryName,
  103.                     kDirectoryNameMaxBytes
  104.                 );
  105.                 /*
  106.                  * Finally, add this directory to the list of active
  107.                  * directories. We really don't need an operating
  108.                  * system queue here, but Enqueue does what we want.
  109.                  */
  110.                 Enqueue((QElemPtr) newDirectory, &INFO.directoryQHdr);
  111.             }
  112.             else {
  113.                 /*
  114.                  * We couldn't allocate memory for this directory.
  115.                  * All we can do is close the PAB. Ignore any error
  116.                  * from ADASClosePAB since we have a real error now.
  117.                  */ 
  118.                 (void) ADASClosePAB(pabRefNum);
  119.             }
  120.         }
  121.         LogStatus('AddS', status, "\pAddDirectory exit");
  122.         if (status != noErr)
  123.             LogRString('AddD', pb->addDSAMDirectoryPB.directoryName);
  124.         return (status);
  125. }
  126.